package com.alquimia.domain;

import java.io.Serializable;
import java.util.UUID;

/**
 * Created by Ivo on 29/05/2014.
 */
public abstract class Unicidad implements Identidad, Serializable {

    private static final long serialVersionUID = 1L;

    private UUID id;

    protected Unicidad(UUID aId) {

        this();
        this.setId(aId);
    }

    protected Unicidad() {
        super();
    }


    public UUID id() {
        return this.id;
    }

    @Override
    public boolean equals(Object aObject) {

        boolean equalObjects = false;
        if (aObject != null && this.getClass() == aObject.getClass()) {
            Unicidad unicidad = (Unicidad) aObject;
            equalObjects = this.id().equals(unicidad.id());
        }

        return equalObjects;
    }

    @Override
    public int hashCode() {
        int hashCodeValue = +(this.hashValorPrimo() * this.hashValorPrincipal()) + this.id().hashCode();

        return hashCodeValue;
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + " [id=" + id + "]";
    }

    protected abstract int hashValorPrimo();

    protected abstract int hashValorPrincipal();

    private void setId(UUID aId) {
        if (aId == null)
            throw new IllegalArgumentException("La identidad es requerida.");

        this.id = aId;
    }
}
